///////////////////////////////////////////////////////////
//  CCreateTemplateView.cpp
//  Implementation of the Class CCreateTemplateView
//  Created on:      21-Sep-2013 9:37:15 AM
//  Original author: Jakkaphan Aiemcharoenjit
///////////////////////////////////////////////////////////

#include "CCreateTemplateView.h"
#include "ControlCommand.h"
#include "CurrentCommand.h"
#include "IHeader.h"
#include "Item.h"
#include "DataFactory.h"
#include "stdafx.h"

using namespace UI;
using namespace UI::CMD;

CCreateTemplateView::CCreateTemplateView(IWindowDirector* director)
{
  this->m_type = IViewCtrl::CREATETEMPLATEVIEW_T;
  this->m_parrentWnd = director;
  this->m_templatePage = NULL;
  this->m_currentRow = -1;
  
  // call initialize for create all UI.
  Initialize();
}


CCreateTemplateView::~CCreateTemplateView()
{
  RemovePage();

  //if(this->m_templatePage)
  //  delete this->m_templatePage;
  //this->m_templatePage = NULL;
}

UI::IViewCtrl::ViewType CCreateTemplateView::GetType() const 
{

	return this->m_type;
}


void CCreateTemplateView::Initialize()
{
  this->SetAttribute<int>("x1", 0);
  this->SetAttribute<int>("y1", 0);
  this->SetAttribute("width", "100%");
  this->SetAttribute("height", "90%");
  this->SetAttribute("backgroundColour", CColour(COLOUR_PAGE));

  // Create navigationbar and set right button name
  this->m_navigationBar = CreateNavigationBar(CAttributes()
    .Set("name", "navBar")
    .Set("title", "Create template")
    .Set("rightButtonCaption", "Save")
    .Set("leftButtonCaption", "Back")
    .Set("x1",      0)
    .Set("y1",      0)
    .Set("width",   "100%")
    .Set("height",  "10%"));

  // Setting event handler for handling navigation bar click
  this->m_navigationBar->SetEventHandler("clicknavigationbar", this, &CCreateTemplateView::OnClickedNevigationBar);

  // Add navigation bar in view
  this->AddChild(this->m_navigationBar);

  // Create tool bar
  //this->m_toolBar = CreateToolBar(CAttributes()
  //  .Set("name",    "toolbar")
  //  .Set("x1",      "0%")
  //  .Set("y1",      "10%")
  //  .Set("width",   "100%")
  //  .Set("height",  "10%"));

  //// Create tool bar button for New, Edit, Remove and View
  //CToolBarButtonPtr toolButton = CreateToolBarButton(CAttributes()
  //  .Set("name",    "ToolBarNewItem")
  //  .Set("caption", "Add"));

  //this->m_toolBar->AddChild(toolButton);

  //toolButton = CreateToolBarButton(CAttributes()
  //  .Set("name",    "ToolBarInsertItem")
  //  .Set("caption", "Insert"));

  //this->m_toolBar->AddChild(toolButton);

  //toolButton = CreateToolBarButton(CAttributes()
  //  .Set("name",    "ToolBarEditItem")
  //  .Set("caption", "Edit"));

  //this->m_toolBar->AddChild(toolButton);

  //toolButton = CreateToolBarButton(CAttributes()
  //  .Set("name",    "ToolBarDeleteItem")
  //  .Set("caption", "Delete"));

  //this->m_toolBar->AddChild(toolButton);

  //toolButton = CreateToolBarButton(CAttributes()
  //  .Set("name",    "ToolBarChoiceItem")
  //  .Set("caption", "Choice"));

  //this->m_toolBar->AddChild(toolButton);


  // Setting event handler for handling toolbar click
  //this->m_toolBar->SetEventHandler("clicktoolbar", this, &CCreateTemplateView::OnClickedToolBar);

  // Add tool bar in view
  //this->AddChild(this->m_toolBar);

  CButtonPtr buttonItem = CreateButton(CAttributes()
    .Set("name", "buttonAdd")
    .Set("x1",    "1%")
    .Set("y1",    "11%")
    .Set("width", "18%")
		//.Set("width", 70)
		.Set("height", "10%")
    .Set("caption", "")
		.Set("normal.image","AddItem_ON.bmp")
		.Set("pressed",     CAttributes().Set("image",   "AddItem_OFF.bmp"))
		.Set("disabled",    CAttributes().Set("image",   "AddItem_OFF.bmp")));
  this->AddChild(buttonItem);
  buttonItem->SetEventHandler("click", this, &CCreateTemplateView::OnClickedAdd);

  buttonItem = CreateButton(CAttributes()
    .Set("name", "buttonInsert")
    .Set("x1",    "20%")
    .Set("y1",    "11%")
    .Set("width", "19%")
    .Set("caption", "Insert"));

  this->AddChild(buttonItem);
  buttonItem->SetEventHandler("click", this, &CCreateTemplateView::OnClickedInsert);

  buttonItem = CreateButton(CAttributes()
    .Set("name", "buttonEdit")
    .Set("x1",    "40%")
    .Set("y1",    "11%")
    .Set("width", "19%")
    .Set("caption", "Edit"));

  this->AddChild(buttonItem);
  buttonItem->SetEventHandler("click", this, &CCreateTemplateView::OnClickedEdit);

  buttonItem = CreateButton(CAttributes()
    .Set("name", "buttonDelete")
    .Set("x1",    "60%")
    .Set("y1",    "11%")
    .Set("width", "19%")
    .Set("caption", "Delete"));

  this->AddChild(buttonItem);
  buttonItem->SetEventHandler("click", this, &CCreateTemplateView::OnClickedRemove);

  buttonItem = CreateButton(CAttributes()
    .Set("name", "buttonChoice")
    .Set("x1",    "80%")
    .Set("y1",    "11%")
    .Set("width", "19%")
    .Set("caption", "Choice"));

  this->AddChild(buttonItem);
  buttonItem->SetEventHandler("click", this, &CCreateTemplateView::OnClickedChoices);

  this->m_table = CreateTable(CAttributes()
    .Set("name",    "TablePages")
    .Set("x1",      0)
    .Set("y1",      "20%")
    .Set("width",   "100%")
    .Set("height",  "80%")
    .Set("alignH",  "top"));

  this->m_table->SetEventHandler("selectrow", this, &CCreateTemplateView::OnSelectedTable);

  // Add table in view
  this->AddChild(this->m_table);

  this->m_alretDlg = CreateAlertDialog(CAttributes()
    .Set("name",                    "AlertDialog")
    .Set("title",                   "Save")
    .Set("message",                 "Would you need to save this template?")
    .Set("positiveButtonCaption",   "Yes")
    .Set("negativeButtonCaption",   "No")
    .Set("neutralButtonCaption",    "Cancel"));


  this->m_alretDlg->SetEventHandler("dismissalertdialog", this, &CCreateTemplateView::OnAlertButtonClick);
}


void CCreateTemplateView::Refresh()
{
  int iChildItems = this->m_templatePage->CountChilds();

  int iRows = (int)this->m_tableRows.size();
  // Remove all row in table
  for(int index = 0; index < iRows; index++)
    this->m_table->RemoveChild(this->m_tableRows[index].second);

  // **** Find the method to delete auto pointer ****
  this->m_tableRows.clear();
  this->m_pageIndexs.clear();

  //std::string labelText = "";

  int iRowCount = 0;

  for(int index = 0; index < iChildItems; index++)
  {
    IObject* item = this->m_templatePage->GetChild(index);
    switch(item->GetType())
    {
    case IObject::HEARDER_T:
      {
        //char tmp[0xff];
        //snprintf(tmp, 0xff, "HeaderTable%d", index);

        IHeader* header = dynamic_cast<IHeader*>(item);

        //labelText = header->GetName();

        //AddRow(item, tmp, labelText);
        AddTableRow(item);

        this->m_pageIndexs[iRowCount] = std::make_pair(index, -1);

        iRowCount++;

        // Add child
        int iChildCount = header->CountChilds();

        for(int childIndex = 0; childIndex < iChildCount; childIndex++)
        {
          //snprintf(tmp, 0xff, "ChildItemTable%d", (childIndex + 1) * (index + 1));

          IObject* childItem = header->GetChild(childIndex);

          //labelText = dynamic_cast<IItem*>(childItem)->GetName();
          //labelText = "   - " + labelText;

          AddTableRow(childItem, true);
          //AddRow(childItem, tmp, labelText);

          this->m_pageIndexs[iRowCount] = std::make_pair(index, childIndex);

          iRowCount++;
        }
      }
      break;
    case IObject::ITEM_T:
      {
        //char tmp[0xff];
        //snprintf(tmp, 0xff, "ItemTable%d", index);

        //labelText = dynamic_cast<IItem*>(item)->GetName();
        //labelText = "   - " + labelText;

        //AddRow(item, tmp, labelText);
        AddTableRow(item);

        this->m_pageIndexs[iRowCount] = std::make_pair(index, -1);

        iRowCount++;
      }
      break;
    default: break;
    }

  }

  if(this->m_currentRow != -1)
    this->m_table->SetAttribute("selected", this->m_currentRow);
}


void CCreateTemplateView::ShowView(bool show)
{
  this->SetAttribute("visible", show);
}


bool CCreateTemplateView::OnClickedAdd(CButton* button)
{
  ControlCommand::GetInstance()->OnNew(ControlCommand::ITEM_CTRL);
  this->m_parrentWnd->OnShowView(this, IViewCtrl::CREATEITEMVIEW_T);
  return true;
}


void CCreateTemplateView::OnClickedBack()
{

}


void CCreateTemplateView::OnClickedSave()
{

}


bool CCreateTemplateView::OnClickedChoices(CButton* button)
{
  ControlCommand::GetInstance()->OnNew(ControlCommand::CHOICE_CTRL);
  this->m_parrentWnd->OnShowView(this, IViewCtrl::CREATECHOICEVIEW_T);
  return true;
}


void CCreateTemplateView::OnClickedSwap()
{

}


bool CCreateTemplateView::OnClickedRemove(CButton* button)
{
  if(this->m_currentRow != -1 && this->m_templatePage->CountChilds() > 0)
  {
    IObject* item = this->m_tableRows[this->m_currentRow].first;
    switch(item->GetType())
    {
    case IObject::HEARDER_T:
      {
        this->m_templatePage->RemoveChild(this->m_pageIndexs[this->m_currentRow].first);
      }
      break;
    case IObject::ITEM_T:
      {
        int childInPageIndex = this->m_pageIndexs[this->m_currentRow].first;
        int childInHeaderIndex = this->m_pageIndexs[this->m_currentRow].second;
        if(childInHeaderIndex != -1)
        {
          IHeader* header = dynamic_cast<IHeader*>(this->m_templatePage->GetChild(childInPageIndex));
          header->RemoveChild(childInHeaderIndex);
        }
        else
        {
          this->m_templatePage->RemoveChild(this->m_pageIndexs[childInPageIndex].first);
        }
      }
      break;
    default: break;
    }

    this->m_currentRow = -1;
    Refresh();
  }
  return true;
}

bool CCreateTemplateView::OnClickedEdit(CButton* button)
{
  if(this->m_currentRow != -1)
  {
    ControlCommand::GetInstance()->OnEdit(ControlCommand::ITEM_CTRL);
    this->m_parrentWnd->OnShowView(this, IViewCtrl::CREATEITEMVIEW_T);
  }
  return true;
}


bool CCreateTemplateView::OnClickedInsert(CButton* button)
{
  if(this->m_currentRow != -1)
  {
    ControlCommand::GetInstance()->OnInsert();
    this->m_parrentWnd->OnShowView(this, IViewCtrl::CREATEITEMVIEW_T);
  }
  return true;
}


void CCreateTemplateView::CreatePage()
{

}


IPage* CCreateTemplateView::GetPage()
{
  return this->m_templatePage;
}


void CCreateTemplateView::SetPage(IPage* page)
{
  RemovePage();
  this->m_templatePage = page;
}

void UI::CCreateTemplateView::NewPage()
{
  RemovePage();
  this->m_templatePage = Data::DataFactory::CreatePage();
}

void CCreateTemplateView::RemovePage()
{
  this->m_currentRow = -1;
  this->m_currentItem = NULL;

  if(this->m_templatePage)
    delete this->m_templatePage;
  this->m_templatePage = NULL;
}

bool UI::CCreateTemplateView::OnClickedNevigationBar( CNavigationBar* navigationBar, int button )
{
  switch(button)
  {
  case S3E_NUI_NAVIGATION_BAR_BUTTON_LEFT:
    {
      this->m_alretDlg->Show();
      /*ControlCommand::GetInstance()->OnBack(ControlCommand::TEMPLATE_CTRL);
      this->m_parrentWnd->OnShowView(this, IViewCtrl::TEMPLATEVIEW_T);*/ 
    }
    break;
  case S3E_NUI_NAVIGATION_BAR_BUTTON_RIGHT:
    {
      switch(CurrentCommand::GetInstance()->GetNewOrEditCommand())
      {
      case ICommand::NEWTEMPLATE_CMD:
        {
          this->m_parrentWnd->OnShowView(this, IViewCtrl::SAVEVIEW_T); 
        }
        break;
      case ICommand::EDITTEMPLATE_CMD:
        {
          ControlCommand::GetInstance()->OnSave(ControlCommand::TEMPLATE_CTRL);
          this->m_parrentWnd->OnShowView(this, IViewCtrl::TEMPLATEVIEW_T); 
        }
        break;
      default: break;
      }
    }
    break;
  default: break;
  }
  return true;
}

bool UI::CCreateTemplateView::OnClickedToolBar( CToolBar* toolBar, int button )
{
  switch(button)
  {
  case 0: // Add Item button
    {
      ControlCommand::GetInstance()->OnNew(ControlCommand::ITEM_CTRL);
      this->m_parrentWnd->OnShowView(this, IViewCtrl::CREATEITEMVIEW_T);
      
    }
    break;
  case 1: // Insert Item button
    {
      if(this->m_currentRow != -1)
      {
        ControlCommand::GetInstance()->OnInsert();
        this->m_parrentWnd->OnShowView(this, IViewCtrl::CREATEITEMVIEW_T);
      }
    }
    break;
  case 2: // Edit Item button
    {
      ControlCommand::GetInstance()->OnEdit(ControlCommand::ITEM_CTRL);
      this->m_parrentWnd->OnShowView(this, IViewCtrl::CREATEITEMVIEW_T);
    }
    break;
  case 3: // Delete Item button
    {
      if(this->m_currentRow != -1 && this->m_templatePage->CountChilds() > 0)
      {
        IObject* item = this->m_tableRows[this->m_currentRow].first;
        switch(item->GetType())
        {
        case IObject::HEARDER_T:
          {
            this->m_templatePage->RemoveChild(this->m_pageIndexs[this->m_currentRow].first);
          }
          break;
        case IObject::ITEM_T:
          {
            int childInPageIndex = this->m_pageIndexs[this->m_currentRow].first;
            int childInHeaderIndex = this->m_pageIndexs[this->m_currentRow].second;
            if(childInHeaderIndex != -1)
            {
              IHeader* header = dynamic_cast<IHeader*>(this->m_templatePage->GetChild(childInPageIndex));
              header->RemoveChild(childInHeaderIndex);
            }
            else
            {
              this->m_templatePage->RemoveChild(this->m_pageIndexs[childInPageIndex].first);
            }
          }
          break;
        default: break;
        }

        this->m_currentRow = -1;
        Refresh();
      }
    }
    break;
  case 4: // Choice Item button
    {
      ControlCommand::GetInstance()->OnNew(ControlCommand::CHOICE_CTRL);
      this->m_parrentWnd->OnShowView(this, IViewCtrl::CREATECHOICEVIEW_T);
       
    }
    break;
  default: break;
  }
  return true;
}

bool UI::CCreateTemplateView::OnSelectedTable( CTable* table, int tab )
{
  this->m_currentRow = tab;
  if(tab != -1)
    this->m_currentItem = this->m_tableRows[tab].first;
  return true;
}

void UI::CCreateTemplateView::AddRow( IObject* item, std::string labelName, std::string labelText )
{
  CTableItemPtr tableItem = CreateTableItem(CAttributes()
    .Set("width",   "100%")
    .Set("height",  "50"));

  CLabelPtr label = CreateLabel(CAttributes()
    .Set("name",    labelName.c_str())
    .Set("caption", labelText.c_str())
    .Set("width", "100%")
    .Set("height", "100%")
    );

  tableItem->AddChild(label);

  this->m_table->AddChild(tableItem);

  this->m_tableRows.push_back(std::make_pair(item, tableItem));
}

void UI::CCreateTemplateView::AddTableRow( IObject* item, bool isChild /*= false*/ )
{
  CTableItemPtr tableItem = CreateTableRow(item, isChild);

  this->m_table->AddChild(tableItem);

  this->m_tableRows.push_back(std::make_pair(item, tableItem));
}

void UI::CCreateTemplateView::SetTitleView( const std::string& text )
{
  this->m_navigationBar->SetAttribute("title", text.c_str());
}

IObject* UI::CCreateTemplateView::GetCurrentData()
{
  IObject* currentData = NULL;
  if(this->m_currentRow != -1)
  {
    int childPageIndex = this->m_pageIndexs[this->m_currentRow].first;
    int chlidHeaderIndex = this->m_pageIndexs[this->m_currentRow].second;
    IObject* data = this->m_templatePage->GetChild(childPageIndex);
    if(chlidHeaderIndex != -1)
    {
      IHeader* header = dynamic_cast<IHeader*>(data);
      currentData = header->GetChild(chlidHeaderIndex);
    }
    else
      currentData = data;
  }
  return currentData;
}

void UI::CCreateTemplateView::AppendData( IObject* data )
{
  /*if(this->m_currentRow != -1)
  {
  switch(this->m_currentItem->GetType())
  {
  case IObject::ITEM_T:
  {
  IItem* item = dynamic_cast<IItem*>(this->m_currentItem);
  switch(item->GetParent()->GetType())
  {
  case IObject::PAGE_T:
  {
  dynamic_cast<IPage*>(item->GetParent())->AppendChild(data);
  }
  break;
  case IObject::HEARDER_T:
  {
  dynamic_cast<IHeader*>(item->GetParent())->AppendChild(data);
  }
  break;
  default: break;
  }
  }
  break;
  case IHeader::HEARDER_T:
  {
  IHeader* header = dynamic_cast<IHeader*>(this->m_currentItem);
  switch(header->GetParent()->GetType())
  {
  case IObject::PAGE_T:
  {
  dynamic_cast<IPage*>(header->GetParent())->AppendChild(data);
  }
  break;
  case IObject::HEARDER_T:
  {
  dynamic_cast<IHeader*>(header->GetParent())->AppendChild(data);
  }
  break;
  default: break;
  }
  }
  break;
  default: break;
  }
  }
  else
  {
  this->m_templatePage->AppendChild(data);
  }*/

  switch(data->GetType())
  {
  case IObject::ITEM_T:
    {
      if(this->m_currentRow == -1)
      {
        this->m_templatePage->AppendChild(data);
      }
      else
      {
        switch(this->m_currentItem->GetType())
        {
        case IObject::HEARDER_T:
          {
            dynamic_cast<IHeader*>(this->m_currentItem)->AppendChild(data);
          }
          break;
        case IObject::ITEM_T:
          {
            IItem* item = dynamic_cast<IItem*>(this->m_currentItem);
            IObject* parent = item->GetParent();
            switch(parent->GetType())
            {
            case IObject::PAGE_T:
              {
                this->m_templatePage->AppendChild(data);
              }
              break;
            case IObject::HEARDER_T:
              {
                IHeader* header = dynamic_cast<IHeader*>(parent);
                header->AppendChild(data);
              }
              break;
            default: break;
            }
          }
          break;
        default: break;
        }
      }
    }
    break;
  case IHeader::HEARDER_T:
    {
      this->m_templatePage->AppendChild(data);
    }
    break;
  default: break;
  }
}

void UI::CCreateTemplateView::InsertData( IObject* data )
{
  int indexChildPage = this->m_pageIndexs[this->m_currentRow].first;
  int indexChildHeader = this->m_pageIndexs[this->m_currentRow].second;
  switch(data->GetType())
  {
  case IObject::ITEM_T:
    {
      if(indexChildHeader == -1)
      {
        this->m_templatePage->InsertChild(indexChildPage, data);
      }
      else
      {
        IObject* childPage = this->m_templatePage->GetChild(indexChildPage);
        switch(childPage->GetType())
        {
        case IObject::HEARDER_T:
          dynamic_cast<IHeader*>(childPage)->InsertChild(indexChildHeader, data);
          break;
        case IObject::ITEM_T:
          this->m_templatePage->InsertChild(indexChildPage, data);
          break;
        default: break;
        }
      }
      //if(this->m_currentRow == -1)
      //{
      //  this->m_templatePage->AppendChild(data);
      //}
      //else
      /*{
        switch(this->m_currentItem->GetType())
        {
        case IObject::HEARDER_T:
          {
            dynamic_cast<IHeader*>(this->m_currentItem)->AppendChild(data);
          }
          break;
        case IObject::ITEM_T:
          {

            IItem* item = dynamic_cast<IItem*>(this->m_currentItem);
            IObject* parent = item->GetParent();
            switch(parent->GetType())
            {
            case IObject::PAGE_T:
              {
                this->m_templatePage->AppendChild(data);
              }
              break;
            case IObject::HEARDER_T:
              {
                IHeader* header = dynamic_cast<IHeader*>(parent);
                header->AppendChild(data);
              }
              break;
            default: break;
            }
          }
          break;
        default: break;
        }
      }*/

    }
    break;
  case IHeader::HEARDER_T:
    {
      this->m_templatePage->InsertChild(indexChildPage, data);
    }
    break;
  default: break;
  }

}

void UI::CCreateTemplateView::EditCurrentNameData( const std::string& text )
{
  if(this->m_currentRow != -1)
  {
    switch(this->m_currentItem->GetType())
    {
    case IObject::ITEM_T:
      {
        dynamic_cast<IItem*>(this->m_currentItem)->SetName(text);
      }
      break;
    case IHeader::HEARDER_T:
      {
        dynamic_cast<IHeader*>(this->m_currentItem)->SetName(text);
      }
      break;
    default: break;
    }
  }
}

bool UI::CCreateTemplateView::OnAlertButtonClick( CAlertDialog* dialog, EAlertDialogButton button )
{
  switch(button)
  {
  case IWNUI_ALERT_DIALOG_POSITIVE:
    {
      switch(CurrentCommand::GetInstance()->GetNewOrEditCommand())
      {
      case ICommand::NEWTEMPLATE_CMD:
        {
          this->m_parrentWnd->OnShowView(this, IViewCtrl::SAVEVIEW_T); 
        }
        break;
      case ICommand::EDITTEMPLATE_CMD:
        {
          ControlCommand::GetInstance()->OnSave(ControlCommand::TEMPLATE_CTRL);
          this->m_parrentWnd->OnShowView(this, IViewCtrl::TEMPLATEVIEW_T); 
        }
        break;
      default: break;
      }
    }
    break;
  case IWNUI_ALERT_DIALOG_NEGATIVE:
    {
      ControlCommand::GetInstance()->OnBack(ControlCommand::TEMPLATE_CTRL);
      this->m_parrentWnd->OnShowView(this, IViewCtrl::TEMPLATEVIEW_T);
    }
    break;
  case IWNUI_ALERT_DIALOG_NEUTRAL:
    break;
  default: break;
  }
  return true;
}

CTableItemPtr CCreateTemplateView::CreateTableRow( IObject* item, bool isChild)
{
  CTableItemPtr tableItem = CreateTableItem(CAttributes()
    .Set("width",   "100%")
    .Set("height",  "50"));

  CLabelPtr label;
  std::string labelName = "Lable_";

  switch(item->GetType())
  {
  case IObject::ITEM_T:
    {
      std::string labelText;
      labelText = dynamic_cast<IItem*>(item)->GetName();
      if(isChild)
        labelText = " - " + labelText;
      labelName += labelText;
      label = CreateLabel(CAttributes()
        .Set("name",    labelName.c_str())
        .Set("caption", labelText.c_str())
        .Set("width", "100%")
        .Set("height", "100%")
        .Set("fontColour",       CColour(COLOUR_LABEL))
        );
    }
    break;
  case IObject::HEARDER_T:
    {
      std::string labelText;
      labelText = dynamic_cast<IHeader*>(item)->GetName();
      labelName += labelText;
      label = CreateLabel(CAttributes()
        .Set("name",    labelName.c_str())
        .Set("caption", labelText.c_str())
        .Set("width", "100%")
        .Set("height", "100%")
        .Set("fontStyle",  "bold")
        .Set("fontColour",       CColour(COLOUR_LABEL))
        //.Set("backgroundColour", COLOUR_GREY)
        .Set("shadow",           true)
        .Set("shadowOffset",     CVector2(0, 2))
        .Set("shadowColour",     CColour(COLOUR_WHITE))
        .Set("fontSize",    "large")
        );
    }
    break;
  default: break;
  }

  tableItem->AddChild(label);

  return tableItem;
}
